<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        <ul>
          <li v-for="value in info">{{value}}</li>
        </ul>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      /*

      1. 直接使用delete删除，或添加一个不存的属性，不能保证对象响应特性。
      2. 删除一个对象属性必须使用 $delete(对象,属性)，添加一个对象属性必须使用 $set(对象,属性,值)
      3. 修改已知属性，使用正常对象语法即可
 
      */
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          info: {
            name: "jack",
            age: 20,
            size: {
              h: 100,
              w: 200,
            },
          },
        },
        created() {
          setTimeout(() => {
            // this.info.gender = "boy";//❌
            // delete this.info.name; //❌

            this.$set(this.info, "gender", "boy"); //✔
            this.$set(this.info.size, "gender", "boy"); //✔
            this.$delete(this.info, "name"); //✔
            this.info.size.w = 1000;
            console.log(this.info);
          }, 3000);
        },
      });
    </script>
  </body>
</html>
